<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021-3-5
  Time: 22:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    //作用域不同 page->request->session->application
    pageContext.setAttribute("n1", "hll"); //只在一个页面有效
    request.setAttribute("n2", "hll"); //只在一次请求中有效,请求转发会附带
    session.setAttribute("n3", "hll"); //只在一次会话有效,任意servlet都能获取，一个client一个session
    application.setAttribute("n4", "hll"); //服务器运行时有效,关闭后无效,惟一的
%>

<%
    String name1 = (String) pageContext.getAttribute("n1");
    String name2 = (String) pageContext.getAttribute("n2");
    String name3 = (String) pageContext.getAttribute("n3");
    String name4 = (String) pageContext.getAttribute("n4");
%>
<%--EL表达式能直接取各种内置对象设置的属性--%>
<h1>${n1}</h1>
<h1><%=name1%>
</h1>
</body>
</html>
